package com.kk.springmvc.demo.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kk.springmvc.demo.bean.PersonDTO;
import com.kk.springmvc.demo.common.anno.LogAround;
import com.kk.springmvc.demo.dao.PersonMapper;
import com.kk.springmvc.demo.dao.model.Person;
import com.kk.springmvc.demo.service.IPersonService;

/**
* PersonServiceImpl.java
* 类说明 TODO
*
* @author chengkai
* @date  2017年6月9日 下午3:23:05
*/
@Service
public class PersonServiceImpl implements IPersonService {
    
    @Autowired
    private PersonMapper personMapper;

    @Override
    public void create(PersonDTO personDTO) {
        Person person = new Person();
        BeanUtils.copyProperties(personDTO, person);
        personMapper.insert(person);
    }

    @LogAround
    @Override
    public List<PersonDTO> list(int pageNum) {
        PageHelper.startPage(pageNum, 2);
        List<Person> personList = personMapper.selectAll();
        List<PersonDTO> personDTOList = new Page<>();
        BeanUtils.copyProperties(personList, personDTOList);
        for (Person person : personList) {
            PersonDTO personDTO = new PersonDTO();
            BeanUtils.copyProperties(person, personDTO);
            personDTOList.add(personDTO);
        }
        return personDTOList;
    }

}
